$(function () {
    var pageNum = 1, pageSize = 10, dataCount = 0;
    let S_arr = [];
    var dataList = [];

    function requestData() {
        const userId = sessionStorage.getItem('userId');
        $.ajax({
            timeout: 30000,
            url: window.Http + "/property/infoEvaluate/list",// /property/datarawGovernLog/list
            type: 'GET',
            headers: {
                'Authorization': "Bearer " + sessionStorage.getItem('Token')
            },
            data: { pageNum: pageNum,
                pageSize: pageSize,
                userId: userId },
            success: function (res) {
                if (res.code == 200) {
                    $("#myConfigureTable tbody").empty();
                    dataList = res.rows || [];
                    console.log('dataList', dataList)
                    if (res.rows && res.rows.length > 0) {
                        let html = "";
                        let statushtml = "";
                        let state = "正常";
                        let herfUrl = "";
                        // let productPrice ; // 产品价格
                        res.rows.forEach(function (val, index) {
                            if (val.goodsType == 1) {
                                herfUrl = "./productDetail.html?serverId=" + val.goodsId + "&goodsType=" + val.goodsType;
                            } else {
                                herfUrl = "./productDetail.html?directoryId=" + val.goodsId + "&goodsType=" + val.goodsType;
                            }
                            switch (val.status || 0) {
                                case 0:
                                    state = "已治理";
                                    break;
                                default:
                                    state = "未治理";
                                    break;
                            }
                            html += `<tr  dataId='${val.id}' dataStatus='${val.status}'>
    <th scope="row" style="text-align: center;">` + (index + 1) + `</th>
    <td style="text-align: center;">` + `${val.relevanceName || '—'}` + `</td>
    <td style="text-align: center;">` + state + `</td>
    <td style="text-align: center;">` + `${val.afterScore || '—'}` + `</td>
    <td style="text-align: center;">` + `${val.beforeScore || '—'}` + `</td>
    <td style="text-align: center;">` + `${val.remark ? val.remark : '—'}` + `</td>
</tr>
`
                            S_arr.push(val.id)
                        })
                        $("#myConfigureTable tbody").append(html);
                    } else {
                        let html = `<tr><td scope="row" colspan="8" style="text-align:center">暂无数据</td></tr>`
                        $("#myConfigureTable tbody").append(html);
                    }
                    dataCount = res.total || 0;
                    if (pageNum == 1) {
                        layui.laypage.render({
                            elem: 'myConfigureTablePage', //注意，这里的 test1 是 ID，不用加 # 号
                            count: dataCount, //数据总数，从服务端得到
                            limit: pageSize,
                            jump: function (obj, first) {
                                if (!first) {
                                    pageNum = obj.curr;
                                    pageSize = obj.limit;
                                    requestData();
                                }
                            }
                        });
                    }

                }

            }
        })
    }

    requestData();
    parame = {
        "auditResult": "",
        "id": 0,
        "operateType": 1,
        "status": -1
    }
    // 禁用/启用 /engine/apply/operate
    $('#myConfigureTable tbody').delegate('.Disable', 'click', function () {
        let id = $(this).parents('[dataId]').attr('dataid')
        parame.id = +id
        if ($('.Disable').html() == '禁用') {
            parame.status = 1
            $(`[dataId="${id}"] .Disable`).html('启用')
            $(`[dataId="${id}"] .Disable`).removeClass('layui-btn-danger')
            $.ajax({
                timeout: 30000,
                url: window.Http + "/engine/apply/operate",
                type: 'POST',
                headers: {
                    'Authorization': "Bearer " + sessionStorage.getItem('Token')
                },
                contentType: 'application/json',
                data: JSON.stringify(parame),
                success: function (res) {
                    requestData();
                }
            })
        } else {
            parame.status = -1
            $(`[dataId="${id}"] .Disable`).html('禁用')
            $(`[dataId="${id}"] .Disable`).addClass('layui-btn-danger')
            $.ajax({
                timeout: 30000,
                url: window.Http + "/engine/apply/operate",
                type: 'POST',
                headers: {
                    'Authorization': "Bearer " + sessionStorage.getItem('Token')
                },
                contentType: 'application/json',
                data: JSON.stringify(parame),
                success: function (res) {
                    requestData();
                }
            })
        }
    })
    //查看引擎配置信息
    $('#myConfigureTable tbody').delegate('.configuration', 'click', function () {
        let id = $(this).parents('[dataId]').attr('dataid');
        let obj;
        dataList.forEach((value, index) => {
            if (id == value.id) {
                obj = value;
            }
        })
        layui.layer.open({
            title: '提示',
            content: obj.engineConfig,
            area: '600px',

        });
    })
})
